algalcommand.script
Class FileIO

java.lang.Object
  extended by algalcommand.script.FileIO

public class FileIO
extends java.lang.Object

This class is to provide local file operations to the scripts

Copyright Owner: Michigan State University, license number TEC2011-002101Prov


Field Summary
 java.lang.String SCRIPT_NAME
          This is the name of this object from within the javascript
 
Constructor Summary
FileIO(java.lang.String pbrkey)
           
 
Method Summary
 java.lang.Object loadVariable(java.lang.String name)
          This is the counter part to the saveVariable(..) methods.
 java.lang.String saveReadLocalFile(java.lang.String filepath)
          Reads the contents of the specified file as text.
 void saveTextToLocalFile(java.lang.String txt, java.lang.String filepath)
          Saves a block of text to a given file path relative to the program folder.
 void saveVariable(boolean v, java.lang.String name)
          Saves a variable to a temporary file that will persist after the program closes.
 void saveVariable(double v, java.lang.String name)
          Saves a variable to a temporary file that will persist after the program closes.
 void saveVariable(int v, java.lang.String name)
          Saves a variable to a temporary file that will persist after the program closes.
 void saveVariable(long v, java.lang.String name)
          Saves a variable to a temporary file that will persist after the program closes.
 void saveVariable(java.lang.String v, java.lang.String name)
          Saves a variable to a temporary file that will persist after the program closes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCRIPT_NAME

public final java.lang.String SCRIPT_NAME
This is the name of this object from within the javascript

See Also:
Constant Field Values
Constructor Detail

FileIO

public FileIO(java.lang.String pbrkey)
Method Detail

saveVariable

public void saveVariable(boolean v,
                         java.lang.String name)
                  throws java.io.IOException
Saves a variable to a temporary file that will persist after the program closes.

Parameters:
v - The variable to save
name - The name of the variable
Throws:
java.io.IOException - Thrown if there was a problem saving to the file

saveVariable

public void saveVariable(int v,
                         java.lang.String name)
                  throws java.io.IOException
Saves a variable to a temporary file that will persist after the program closes.

Parameters:
v - The variable to save
name - The name of the variable
Throws:
java.io.IOException - Thrown if there was a problem saving to the file

saveVariable

public void saveVariable(long v,
                         java.lang.String name)
                  throws java.io.IOException
Saves a variable to a temporary file that will persist after the program closes.

Parameters:
v - The variable to save
name - The name of the variable
Throws:
java.io.IOException - Thrown if there was a problem saving to the file

saveVariable

public void saveVariable(double v,
                         java.lang.String name)
                  throws java.io.IOException
Saves a variable to a temporary file that will persist after the program closes.

Parameters:
v - The variable to save
name - The name of the variable
Throws:
java.io.IOException - Thrown if there was a problem saving to the file

saveVariable

public void saveVariable(java.lang.String v,
                         java.lang.String name)
                  throws java.io.IOException
Saves a variable to a temporary file that will persist after the program closes.

Parameters:
v - The variable to save
name - The name of the variable
Throws:
java.io.IOException - Thrown if there was a problem saving to the file

loadVariable

public java.lang.Object loadVariable(java.lang.String name)
                              throws java.io.IOException
This is the counter part to the saveVariable(..) methods. It reads from the same file that the corresponding saveVariable(..) function would have put the data. It returns the most appropriate object for that variable if it is a number, otherwise, it returns a String.

Parameters:
name - The name of the variable
Returns:
A Boolean, Number, or String object, depending on the content of the file. Returns null if the file wasn't found.
Throws:
java.io.IOException - Thrown if there was a problem saving to the file

saveTextToLocalFile

public void saveTextToLocalFile(java.lang.String txt,
                                java.lang.String filepath)
                         throws java.io.IOException
Saves a block of text to a given file path relative to the program folder.

Parameters:
txt - The text to save to the file
filepath - The relative (a.k.a. local) filepath (e.g. "notes\t0.txt" will save the text to the file C:\Program Files\AlgalCommand\notes\t0.txt if C:\Program Files\AlgalCommand is the program directory for AlgalCommand)
Throws:
java.io.IOException - Thrown if the file could not be written to, which often means that there is a folder of the same name as the file.

saveReadLocalFile

public java.lang.String saveReadLocalFile(java.lang.String filepath)
                                   throws java.io.IOException
Reads the contents of the specified file as text. If the file does not exist or is empty, then an empty string is returned.

Parameters:
filepath - The relative (a.k.a. local) filepath (e.g. "notes\t0.txt" will read the text from the file C:\Program Files\AlgalCommand\notes\t0.txt if C:\Program Files\AlgalCommand is the program directory for AlgalCommand)
Returns:
The content of the file, or an empty string
Throws:
java.io.IOException - Thrown if the file cannot be read (e.g. filepath points to a folder).